package com.ruoyi.web.controller.xcx;

import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.domain.TxcheckVO;
import com.ruoyi.common.utils.Assert;
import com.ruoyi.system.domain.AUser;
import com.ruoyi.system.service.IAUserService;
import com.ruoyi.system.util.LoginUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序登录
 *
 * @author ruoyi
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/xcx/xcxLogin")
public class XcxLogin extends BaseController {

    @Autowired
    private IAUserService aUserService;

    @PostMapping("/miniLogin")
    public AjaxResult miniLogin(@RequestBody AUser aUser)throws Exception
    {
        return success(aUserService.miniLogin(aUser));
    }

    /**
     * 解密手机号
     * @param aUser
     * @return
     * @throws Exception
     */
    @PostMapping("/getPhone")
    public AjaxResult getPhone(@RequestBody AUser aUser) throws Exception {
        return success(aUserService.getPhone(aUser));
    }

    @GetMapping("/miniLogin/{code}")
    public AjaxResult miniLoginCode(@PathVariable("code") String code)throws Exception
    {
        return success(LoginUtils.loginByOpenId(aUserService.getOpenId(code)));
    }

    @GetMapping("/txCheck")
    public AjaxResult txCheck(TxcheckVO vo)throws Exception
    {
        return success(aUserService.checkTxSecure(vo));
    }

    @GetMapping("/gzhLongin/{code}")
    public AjaxResult gzhLongin(@PathVariable String code) throws Exception {
        return AjaxResult.success(aUserService.backtoken(code));
    }
}
